
<!doctype html>
<html lang="en">
	<head>
		<title>three.js canvas - interactive - cubes</title>
		<meta charset="utf-8">
		<meta name="viewport" content="width=device-width, user-scalable=no, minimum-scale=1.0, maximum-scale=1.0">
		<style>
			body {
				font-family: Monospace;
				background-color: #f0f0f0;
				margin: 0px;
				overflow: hidden;
			}
		</style>
		<script src="http://mrdoob.github.com/three.js/build/Three.js"></script>
		<script src="http://mrdoob.github.com/three.js/examples/js/Stats.js"></script>
		<script src="three/examples/fonts/helvetiker_regular.typeface.js"></script>
		<script src="three/examples/fonts/helvetiker_bold.typeface.js"></script>
		<script src="InputText.js"></script>
		<script src="DropDownList.js"></script>
		<script src="Utils.js"></script>
	</head>
	<body style="background-color:black;">

		

		<script>

			var container, stats;
			var camera, scene, projector, renderer;

			var textMaterial, geometryGlob, particle;

			var objects = [];
			var controls;
			var clock = new THREE.Clock();

			init();
			animate();

			function init() {

				container = document.createElement( 'div' );
				document.body.appendChild( container );

				var info = document.createElement( 'div' );
				info.style.position = 'absolute';
				info.style.top = '10px';
				info.style.width = '100%';
				info.style.textAlign = 'center';
				info.innerHTML = '<a href="http://github.com/mrdoob/three.js" target="_blank">three.js</a> - clickable objects';
				container.appendChild( info );

				camera = new THREE.PerspectiveCamera( 70, window.innerWidth / window.innerHeight, 1, 10000 );
				camera.position.set( 0, 300, 500 );


				controls = new THREE.FirstPersonControls( camera );
				controls.movementSpeed = 1000;
				controls.lookSpeed = 0.05;
				//controls.noFly = true;
				//controls.lookVertical = false;


				scene = new THREE.Scene();

				scene.add( camera );

				//var geometry = new THREE.CubeGeometry( 100, 100, 100 );

				//var geometry = new THREE.TextGeometry( 'testtest fsd sdf ddfsds', {size: 50, height: 3, curveSegments: 1, font: 'helvetiker', weight: 'normal', style: 'normal' } )
				var loader = new THREE.JSONLoader();
				loader.load( "ohpenLogo.js", function ( geometry ) {
					for ( var i = 0; i < 0; i ++ ) {

						var object = new THREE.Mesh( geometry, new THREE.MeshBasicMaterial( { color: Math.random() * 0xffffff, opacity: 0.5 } ) );
						object.position.x = Math.random() * 800 - 400;
						object.position.y = Math.random() * 800 - 400;
						object.position.z = Math.random() * 800 - 400;

						object.scale.x = Math.random() * 2 + 1;
						object.scale.y = Math.random() * 2 + 1;
						object.scale.z = Math.random() * 2 + 1;

						object.rotation.x = ( Math.random() * 360 ) * Math.PI / 180;
						object.rotation.y = ( Math.random() * 360 ) * Math.PI / 180;
						object.rotation.z = ( Math.random() * 360 ) * Math.PI / 180;

						 scene.add( object );

						objects.push( object );
					}
				});
				
				var pointLight = new THREE.PointLight(0xFFFFFF);
				pointLight.position.x = 100;
				pointLight.position.y = -50;
				pointLight.position.z = 50;
				scene.add(pointLight);
				
				textMaterial = new THREE.MeshBasicMaterial( { color: 0xffffff, overdraw: true } )
				var listItems = [new ListItem("Ohpen NL Index Fund","0"),
					new ListItem("Ohpen Europe Index Fund","1"),
					new ListItem("Ohpen America Index Fund","2")];
				
				var inputText = new InputText(scene);
				for ( var i = 0; i < 1; i ++ ) {
					var ddl = new DropDownList(
						scene, 
						camera,
						listItems
					);
				}
				
				projector = new THREE.Projector();

				//renderer = new THREE.WebGLRenderer({antialias: true});
				renderer = new THREE.WebGLRenderer();
				renderer.setSize( window.innerWidth, window.innerHeight );

				container.appendChild( renderer.domElement );

				stats = new Stats();
				stats.domElement.style.position = 'absolute';
				stats.domElement.style.top = '0px';
				container.appendChild( stats.domElement );

				//document.addEventListener( 'mousedown', onDocumentMouseDown, false );

				

			}

			function onDocumentMouseDown( event ) {

				event.preventDefault();

				var vector = new THREE.Vector3( ( event.clientX / window.innerWidth ) * 2 - 1, - ( event.clientY / window.innerHeight ) * 2 + 1, 0.5 );

				projector.unprojectVector( vector, camera );

				var ray = new THREE.Ray( camera.position, vector.subSelf( camera.position ).normalize() );

				var intersects = ray.intersectObjects( objects );

				if ( intersects.length > 0 ) {

					//intersects[ 0 ].object.material.color.setHex( Math.random() * 0xffffff );

					//var particle = new THREE.Mesh( geometryGlob, textMaterial);
					/*textMaterial = new THREE.MeshBasicMaterial( { color: Math.random() * 0xffffff, overdraw: true } )
					particle = new THREE.Mesh(new THREE.TextGeometry( 'SA', {size:50, height:20, curveSegments: 1, font: "helvetiker", weight: "normal", style: "normal" } ), textMaterial);
					particle.position = intersects[ 0 ].point;
					scene.add( particle );*/
					
				}

				/*
				// Parse all the faces
				for ( var i in intersects ) {

					intersects[ i ].face.material[ 0 ].color.setHex( Math.random() * 0xffffff | 0x80000000 );

				}
				*/
				/*for(var k=0;k<1000;k++) {
					var geom = objects[0].geometry;
					var v1 = new THREE.Vector3(0,0,0);
					var v2 = new THREE.Vector3(0,500,0);
					var v3 = new THREE.Vector3(0,500,500);

					geom.vertices.push(v1);
					geom.vertices.push(v2);
					geom.vertices.push(v3);

					geom.faces.push( new THREE.Face3( 8, 9, 10 ) );
				}*/
			}

			//

			function animate() {

				requestAnimationFrame( animate );

				render();
				stats.update();

			}

			var radius = 600;
			var theta = 0;

			function render() {

				/*theta += 0.2;

				camera.position.x = radius * Math.sin( theta * Math.PI / 360 );
				camera.position.y = radius * Math.sin( theta * Math.PI / 360 );
				camera.position.z = radius * Math.cos( theta * Math.PI / 360 );
				camera.lookAt( scene.position );*/
				controls.update(clock.getDelta());

				renderer.render( scene, camera );

			}

		</script>

	</body>
</html>
